package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Author Yjr
 * @Date 2025/5/27 9:50
 */
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;


    @GetMapping("/conditionSearch")
    @ApiOperation("查询历史订单")
    public Result historyOrders(OrdersPageQueryDTO dto) throws Exception {

        return Result.success(ordersService.historyOrders(dto)) ;

    }

    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result findOrdersById(@PathVariable Long id) throws Exception {

        OrderVO ordersVo = ordersService.findOrdersById(id);
        return Result.success(ordersVo);
    }

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result statistics() throws Exception {

        OrderStatisticsVO orderStatisticsVO = ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("cancel")
    @ApiOperation("取消订单")
    public Result cancelOrders(@RequestBody OrdersCancelDTO dto) throws Exception {

        ordersService.cancelOrders(dto);
        return Result.success();
    }

    @PutMapping("confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO dto) throws Exception {
        ordersService.confirm(dto);
        return Result.success();
    }

    @PutMapping("rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO dto) throws Exception {
        ordersService.rejection(dto);
        return Result.success();
    }

    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id) throws Exception {
        ordersService.delivery(id);
        return Result.success();
    }

    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id) throws Exception {
        ordersService.complete(id);
        return Result.success();
    }

}
